#!/usr/bin/env python
# coding:utf-8
#0.1@2007-08-29
import sys, os
def count_f(dir):
	a=1
	c=0
	while a:
		print dir+"MAQ%05d.MP4" % c
		if not os.path.exists( dir+"MAQ%05d.MP4" % c ):
			a=0
		else:
			c+=1
	return 'MAQ%05d.MP4' % c
def conv(file):
	#	-i		input file
	#	-vcodec	force codec
	#	-s		frame size
	#	-r		frame rate
	#	-b		bitrate
	#	-ac		audio channel
	#	-ar		audio sampling frequency
	#	-ab		audio bitrate
	#	-f		force format
	#"ffmpeg -i %s -bitexact -title %s -vcodec h264 -s %s -r 29.97 -b 725 -acodec aac -ac 2 -ar 44100 -ab 128 -f psp -muxvb 725 %s"
	samfc=44100
	vcode="xvid"
	acode="aac"
	vsize="480x272"
	vsize="360x270"
	vrate="725"
	arate="128"
	format="psp"
	title=os.path.splitext( os.path.basename(file) )[0]
	title=title.replace( " ", "_" )
	out_dir="/f/"
	name=count_f( out_dir )
	output=out_dir+"%s" % name
	command="ffmpeg -i '%s' -title '%s' -vcodec %s -s %s -r 29.97 -b %s -acodec %s -ac 2 -ar %s -ab %s -f %s '%s'" % ( file, title, vcode, vsize, vrate, acode, samfc, arate, format, output )
	print command
	os.system( command )		#use the ffmpeg to convert
def main():
	if len(sys.argv) != 1:
		for i in sys.argv:
			if os.path.isfile( i ) and i != sys.argv[0]:		#check the arguments
				conv( i )
if __name__ == '__main__':
	print "Writen by RAh-XePhON"
	print "http://ToKyo-JuPiTer.Blogspot.com/"
	print "jimmy09140456@gmail.com"
	main()
